import {RouterProvider} from 'react-router-dom'
import router from '@/router/index.jsx'
import {useEffect} from 'react'
import { config } from "@/api/index.js";
import useConfigStore from './store/useConfigStore.js'
export default function () {
  const setConfig = useConfigStore(state => state.setConfig)
  const setModuleList = useConfigStore(state => state.setModuleList)
  async function getConfig(){
    const res = await config()
    if (res.result.status_info.status_code === 100) {
      setConfig(res.result.config);
      setModuleList(res.result.module_list);
      document.title = res.result.config.site_title;
      if (res.result.config.gray_mode == 1) {
        // 置灰
        document.documentElement.style.filter = "grayscale(100%)";
      }
    }
  }
  useEffect(() => {
    getConfig()
    if (history.scrollRestoration) {
      history.scrollRestoration = 'manual';
    }
  },[]);
  return (<RouterProvider router={router}/>)
}